package com.codes.service.impl;

import com.codes.dao.BuildingMapper;
import com.codes.model.Building;
import com.codes.service.BuildingSV;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.List;
import java.util.Map;

/**
 * @Date 2020/6/4 10:00
 * @Created by peanut
 */
@Service
public class BuildingImpl implements BuildingSV {

    @Autowired
    private BuildingMapper buildingMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return buildingMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Building record) {
        return 0;
    }

    @Override
    public int insertSelective(Building record) {
        return 0;
    }

    @Override
    public Building selectByPrimaryKey(Integer id) {
        return null;
    }

    @Override
    public int updateByPrimaryKeySelective(Map record) {
        return buildingMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Building record) {
        return 0;
    }

    @Override
    public int insertByMap(Map map) throws Exception{

        int re = 0 ;
        try {
            re = buildingMapper.insertByMap(map);
            int zero = 1/0;
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("service try catch 会导致 回滚失败吗");
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
//        if (0 == 0){
//            System.out.println("抛出异常");
//            throw  new Exception();
//        }

        return re;
    }

    @Override
    public List<Map<String, Object>> getListByMap(Map map) {
        return buildingMapper.getListByMap(map);
    }
}